var path = require('path');

var webpack = require('webpack');
var AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin');
var merge = require('webpack-merge');

var work_path = process.cwd();

var config = require('./base');

var port = 4000;

Object.keys(config.entry).forEach(function (name) {
    config.entry[name] = ['react-hot-loader/patch', `webpack-dev-server/client?http://127.0.0.1:${port}`,'webpack/hot/only-dev-server'].concat(config.entry[name])
})

config = merge(config, {
    devtool: 'cheap-module-inline-source-map',
    plugins: [

        new AddAssetHtmlPlugin({
            filepath: path.join(process.cwd() + '/dll/dll.js'),
            includeSourcemap: false,
        }),

        new webpack.NamedModulesPlugin(),

        new webpack.HotModuleReplacementPlugin(),

        new webpack.DllReferencePlugin({
            manifest: require('../manifest.json'), // 指定manifest.json
            name: 'dll',  // 当前Dll的所有内容都会存放在这个参数指定变量名的一个全局变量下，注意与DllPlugin的name参数保持一致
        }),

        new webpack.DefinePlugin({
            "process.env": { NODE_ENV: JSON.stringify('development') },
            '____WEBPACK_DEBUG': JSON.stringify(true)
        })
    ]
})

module.exports = config;

